home *** CD-ROM | disk | FTP | other *** search
- global gNotes, gCDNotes, gMidiInstruments, gMidiManager, gMidiStartTime, HARP, TIGO, HORN, DRUM, CHIME, BASS, gDonePlayingScript, gNotesToPlay, gInstrumentInCDTrack, gNextEnvLetter, gNextDIRFile, gMIDIPlayTRUE, gInitalized, noteObjs, windowsMIDIXObj, xNAVXOBJ, xCURXOBJ, gCPU, gfileSep, gRootPath, gHDpath, gXobjs, gXOBJPath, gCDpath, gCDName
-
- on InitMIDILoop Instruments, NOTES
- set C to count(Instruments)
- set gMidiInstruments to [:]
- sort(gMidiInstruments)
- set gNotesToPlay to [:]
- repeat with X = 1 to C
- set InstrumentRef to getAt(Instruments, X)
- set instrument to getaProp(gMidiManager, InstrumentRef)
- set instruNotes to value(string(getaProp(NOTES, InstrumentRef)))
- setaProp(gNotesToPlay, InstrumentRef, instruNotes)
- set NoteTotal to count(instruNotes) / 3
- set Data to [#ref: InstrumentRef, #action: #on, #time: 0, #NoteCount: 1, #NoteTotal: NoteTotal]
- setaProp(gMidiInstruments, InstrumentRef, Data)
- setaProp(instrument, #note, getAt(instruNotes, 2))
- setaProp(instrument, #Pointer, 1)
- end repeat
- set gMIDIPlayTRUE to #true
- set gMidiStartTime to the ticks
- end
-
- on playAllRecordedTracksOrCD thenotes, Instruments, donePlayingScript
- set gMIDIPlayTRUE to #true
- if Instruments <> #ALL then
- InitMIDILoop(Instruments, thenotes)
- else
- set InstrumentsList to []
- repeat with X = 1 to 4
- set int to getPropAt(thenotes, X)
- add(InstrumentsList, int)
- end repeat
- InitMIDILoop(InstrumentsList, thenotes)
- end if
- if voidp(donePlayingScript) then
- set gDonePlayingScript to #false
- else
- set gDonePlayingScript to donePlayingScript
- end if
- end
-
- on playOneTrack InstrumentRef, donePlayingScript
- stopPlayAllTracks()
- if getaProp(gNotes, InstrumentRef) <> [] then
- InitMIDILoop(list(InstrumentRef), gNotes)
- if voidp(donePlayingScript) then
- set gDonePlayingScript to #false
- else
- set gDonePlayingScript to donePlayingScript
- end if
- else
- do(donePlayingScript)
- end if
- end
-
- on playCD donePlayingScript
- playAllRecordedTracksOrCD(gCDNotes, #ALL)
- end
-
- on PLAYCDOFF
- stopPlayAllTracks()
- end
-
- on stopPlayAllTracks
- repeat with Intrument in gMidiManager
- set Channel to getaProp(Intrument, #Channel)
- set note to getaProp(Intrument, #note)
- set velocity to getaProp(Intrument, #velocity)
- WriteMIDI(127 + Channel, note, velocity, Channel)
- setaProp(Intrument, #Pointer, 0)
- end repeat
- set gMIDIPlayTRUE to #false
- set gDonePlayingScript to #false
- end
-
- on eraseRecording InstrumentRef
- set instrument to getaProp(gMidiManager, InstrumentRef)
- setaProp(gNotes, InstrumentRef, [])
- setaProp(instrument, #Start, -1)
- setaProp(instrument, #Pointer, 0)
- setaProp(instrument, #stop, 0)
- end
-
- on WriteMIDI code, note, velocity, Channel
- if code = 192 then
- exit
- end if
- if gCPU = #mpc then
- set str to code && note && velocity
- windowsMIDIXObj(mWrite, str)
- else
- if gCPU = #MAC then
- set obj to getAt(noteObjs, Channel)
- if code >= 144 then
- obj(mNoteOn, note, velocity)
- else
- obj(mNoteOff, note)
- end if
- end if
- end if
- end
-
- on noteOn InstrumentRef, note, velocity
- set TickLOC to the ticks
- set InstrumentManager to getaProp(gMidiManager, InstrumentRef)
- set Channel to getaProp(InstrumentManager, #Channel)
- set StartfirstNote to getaProp(InstrumentManager, #Start)
- set StopLastNote to getaProp(InstrumentManager, #stop)
- if (note < 0) or (note > 127) then
- put "Invalid Note:" && note
- set note to 64
- end if
- WriteMIDI(143 + Channel, note, 127, Channel)
- setaProp(InstrumentManager, #note, note)
- if (getaProp(getaProp(gOBJECTS, InstrumentRef), #PlugInMixer) = #true) and (StopLastNote <> -1) then
- if StartfirstNote = -1 then
- setaProp(InstrumentManager, #Start, TickLOC)
- end if
- add(getaProp(gNotes, InstrumentRef), TickLOC - getaProp(InstrumentManager, #Start))
- add(getaProp(gNotes, InstrumentRef), note)
- end if
- end
-
- on noteOff InstrumentRef, note
- set TickLOC to the ticks
- set InstrumentManager to getaProp(gMidiManager, InstrumentRef)
- set Channel to getaProp(InstrumentManager, #Channel)
- set StopLastNote to getaProp(InstrumentManager, #stop)
- WriteMIDI(127 + Channel, getaProp(InstrumentManager, #note), 127, Channel)
- if (getaProp(getaProp(gOBJECTS, InstrumentRef), #PlugInMixer) = #true) and (StopLastNote <> -1) then
- set TimeOffset to TickLOC - getaProp(InstrumentManager, #Start)
- add(getaProp(gNotes, InstrumentRef), TimeOffset)
- setaProp(getaProp(gMidiManager, InstrumentRef), #stop, TickLOC)
- if (TimeOffset > 1800) or (count(getaProp(gNotes, InstrumentRef)) > 179) then
- setaProp(InstrumentManager, #stop, -1)
- else
- setaProp(InstrumentManager, #stop, TickLOC)
- end if
- end if
- end
-
- on midiInterrupt
- set Midilist to value(string(gMidiInstruments))
- repeat with instrument in Midilist
- set TickLOC to the ticks
- if (getaProp(instrument, #time) + gMidiStartTime) > TickLOC then
- next repeat
- end if
- if getaProp(instrument, #action) = #on then
- MidiNoteON(getaProp(instrument, #ref), getaProp(gNotesToPlay, getaProp(instrument, #ref)))
- next repeat
- end if
- MidiNoteOFF(getaProp(instrument, #ref), getaProp(gNotesToPlay, getaProp(instrument, #ref)))
- end repeat
- end
-
- on MidiNoteON IntrumentRef, NOTES
- set Intrument to getaProp(gMidiManager, IntrumentRef)
- set note to getaProp(Intrument, #note)
- set Channel to getaProp(Intrument, #Channel)
- WriteMIDI(143 + Channel, note, 127, Channel)
- set InstanceIntrument to getaProp(gMidiInstruments, IntrumentRef)
- setaProp(InstanceIntrument, #action, #off)
- setaProp(InstanceIntrument, #time, getAt(NOTES, getaProp(Intrument, #Pointer) + 2))
- end
-
- on MidiNoteOFF IntrumentRef, NOTES
- set Intrument to getaProp(gMidiManager, IntrumentRef)
- set note to getaProp(Intrument, #note)
- set Channel to getaProp(Intrument, #Channel)
- WriteMIDI(127 + Channel, note, 127, Channel)
- set InstanceIntrument to getaProp(gMidiInstruments, IntrumentRef)
- set NoteCount to getaProp(InstanceIntrument, #NoteCount)
- if NoteCount >= getaProp(InstanceIntrument, #NoteTotal) then
- deleteProp(gMidiInstruments, IntrumentRef)
- setaProp(getaProp(gMidiManager, IntrumentRef), #Pointer, -1)
- if count(gMidiInstruments) = 0 then
- set gMIDIPlayTRUE to #false
- end if
- else
- set Pointer to getaProp(Intrument, #Pointer) + 3
- setaProp(InstanceIntrument, #NoteCount, NoteCount + 1)
- setaProp(InstanceIntrument, #action, #on)
- setaProp(InstanceIntrument, #time, getAt(NOTES, Pointer))
- setaProp(getaProp(gMidiManager, IntrumentRef), #Pointer, Pointer)
- setaProp(getaProp(gMidiManager, IntrumentRef), #note, getAt(NOTES, Pointer + 1))
- end if
- end
-
- on allNotesOff
- if gCPU = #mpc then
- repeat with instrument = 1 to 6
- repeat with note = 0 to 127
- set str to 128 + (instrument - 1) && note && 0
- windowsMIDIXObj(mWrite, str)
- end repeat
- end repeat
- else
- if gCPU = #MAC then
- repeat with instrument = 1 to 6
- set obj to getAt(noteObjs, instrument)
- if objectp(obj) then
- repeat with Xnote = 0 to 127
- obj(mNoteOff, Xnote)
- set NOW to the timer
- repeat while the timer < (NOW + 0.00001)
- end repeat
- end repeat
- end if
- end repeat
- end if
- end if
- end
-